package com.example.jussi.taopiaopiao;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.example.jussi.alipatstander.AlipayInterface;


/**
 * Created by admin on 2018/12/10.
 */

public class BaseActivity extends Activity implements AlipayInterface {

    protected Activity that;

    /**
     * super.setContentView(layoutResID);
     * 最终调用的系统给我们注入的上下文
     * 而我们要支付宝给我们注入的上下文
     * 所以所有与上下文的方法都必须重写
     * 调用 that 从支付宝拿到的上下文
     * @param layoutResID
     */
    @Override
    public void setContentView(int layoutResID) {
        if(that == null){
            super.setContentView(layoutResID);
        }else{
            that.setContentView(layoutResID);
        }
    }

    @Override
    public <T extends View> T findViewById(int id) {
        if(that == null){
            return super.findViewById(id);
        }else{
            return that.findViewById(id);
        }
    }

    @Override
    public ClassLoader getClassLoader() {
        if(that != null){
            return that.getClassLoader();
        }
        return super.getClassLoader();
    }

    @NonNull
    @Override
    public LayoutInflater getLayoutInflater() {
        if(that != null){
            return that.getLayoutInflater();
        }
        return super.getLayoutInflater();
    }

    @Override
    public Window getWindow() {
        if(that != null){
            return that.getWindow();
        }
        return super.getWindow();
    }

    @Override
    public WindowManager getWindowManager() {
        if(that != null){
            return that.getWindowManager();
        }
        return super.getWindowManager();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {

    }

    @Override
    public void onStart() {

    }

    @Override
    public void onResume() {

    }

    @Override
    public void onPause() {

    }

    @Override
    public void onStop() {

    }

    @Override
    public void onDestroy() {

    }

    @Override
    public void onSaveInstanceState(Bundle outState) {

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return false;
    }

    @Override
    public void onBackPressed() {

    }

    @Override
    public void attach(Activity activity) {
        this.that = activity;
    }
}
